package org.zerg.controller.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zerg.entity.Product;
import org.zerg.service.ProductService;

@Controller
@RequestMapping("/api")
public class ProductController {

	@Autowired
	private ProductService productService;
	
	@RequestMapping(value="/product/{id}", method = RequestMethod.GET,
            produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public List<Product> getProductByCa(@PathVariable(value="id") int id){
		List<Product> list = productService.getProductByCa(id);
		return list;
	}
	
	
	@ResponseBody
	@RequestMapping(value="/productone/{id}", method = RequestMethod.GET,
            produces = {"application/json;charset=UTF-8"})
	public Product getProductOne(@PathVariable(value="id") int id){
		Product product = productService.getProductDelit(id);
		return product;
	}
	
	@ResponseBody
	@RequestMapping(value="/recent/product", method = RequestMethod.GET,
            produces = {"application/json;charset=UTF-8"})
	public List<Product> getRecentProduct(){
		List<Product> list = productService.getRecentProduct();
		return list;
	}
}
